<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collappseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="lhmQueryPart"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isExportExcel="true"
      exportFileName="备件查询.xlsx"
      :onColumnsChange="columns => (this.columns = columns)"
      :isSelectColumn="false"
    >
      <!--列操作-->
      <template slot="controls"> </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getQueryPart2 } from '@/api/repair/queryStatistics/queryPart';

export default {
  name: 'LHMQueryPart',
  components: {},
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: { xhrAbort: true },
      visible: false,
      visible1: false,
      dialogTitle: '',
      fetchApi: getQueryPart2,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      tableData: [],
      ids: []
    };
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '备件代码',
          fieldName: 'PART_NO'
        },
        {
          type: 'INPUT',
          label: '备件名称',
          fieldName: 'PART_NAME'
        },
        {
          type: 'INPUT',
          label: '主组号',
          fieldName: 'MAIN_GROUP_NO'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '备件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '备件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '拼音码',
          dataIndex: 'SPELL_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '批号',
          dataIndex: 'PATCH_ORDER',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '保质期截止日期',
          dataIndex: 'SHELF_DAYS',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '仓库代码',
          dataIndex: 'STORAGE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '仓库名称',
          dataIndex: 'STORAGE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '含税销售单价',
          dataIndex: 'SALES_PRICE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '库存数量',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '可用数量',
          dataIndex: 'USE_DATA',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        // {
        //   title: '可用数量',
        //   dataIndex: 'STOCK_QUANTITY',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '计量单位',
          dataIndex: 'UNIT_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否启用',
          dataIndex: 'ENGINE_NO',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8131'),
          dictItems: this.createDictList('8131'),
          render: props => {
            return <span>{this.createDictText(props.row.ENGINE_NO, '8131')}</span>;
          }
        },
        {
          title: '车型代码',
          dataIndex: 'SERIES',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '车型名称',
          dataIndex: 'SERIES_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
      ];
    },
    selectData(val) {
      this.tableData = val;
    },
    collappseHandle() {},
    addHandle() {
      // 新建
      this.handleType = 'add';
      // this.formData = row;
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit'; // 编辑

      this.showHandler();
    },
    changeHandle(val) {
      if (!val['PART_NO'] & !val['PART_NAME'] & !val['MAIN_GROUP_NO']) {
        return this.$notify.warning({ title: '提示信息', message: '[主组号]或[备件代码]或[备件名称],至少输入一个查询条件!' });
      }
      this.fetchParams.xhrAbort = true;
      this.fetchParams = Object.assign({}, { xhrAbort: false }, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    async saveDialog() {
      let res = {};
      if (this.tableData == null) return;
      res = await addCustomeRgradeUpdatet({ customeRgradeUpdateDTOList: this.tableData });
      if (res.resultCode === 200) {
        this.closeDialog('refresh');
      }
    },
    showHandler() {
      // 显示
      this.dialogTitle = `查看结算记录`;
      this.visible = true;
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
